import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from mpl_toolkits.mplot3d import Axes3D


inputfile = '../process_data/data/kaggle_bike_processed.csv'
outputfile = 'data/lda_dimention_reducted.csv' #降维后的数据

# 读入数据
dataSet = pd.read_csv(inputfile, header = 0) #读入数据

# 得到训练数据和目标值
target = dataSet['count'].values
data = dataSet.drop(['count'], axis=1).values

'''
fig = plt.figure('PCA')
pca = PCA(n_components=2)
pca.fit(data)
print("各主成分的方差值:"+str(pca.explained_variance_))
print("各主成分的方差值比:"+str(pca.explained_variance_ratio_))
X_new = pca.transform(data)
plt.scatter(X_new[:, 0], X_new[:, 1], marker='o',c=target, alpha=0.5)
'''

# fig = plt.figure('LDA')
lda = LinearDiscriminantAnalysis(n_components=3)
lda.fit(data, target)
X_new = lda.transform(data)
# plt.scatter(X_new[:, 0], X_new[:, 1],marker='o',c=target,alpha=0.5)
# plt.show()


pd.DataFrame(X_new).to_csv(outputfile,  index=0, header=0, float_format="%0.4f")